// 监听返回首页
$('.img-return-btn').on('click', function() {
  _hmt.push(['_trackEvent', '120_complex_return_index', 'click', '0']);
});

//监听发送弹幕
$('.send-barrage').on('click', function() {
  _hmt.push(['_trackEvent', '120_complex_send_barrage', 'click', '0']);
});

//监听分享按钮
$('.img-share-btn').on('click', function() {
  _hmt.push(['_trackEvent', '120_complex_share_barrage', 'click', '0']);
});

$(function  () {
	console.log(id);
  $('.img-bg-1').attr('src','../images/cambodia/bg_'+id+'_1.jpg');
  $('.img-bg-2').attr('src','../images/cambodia/bg_'+id+'_2.jpg');
  $('.img-bg-3').attr('src','../images/cambodia/bg_'+id+'_3.jpg');
  $('.img-view-topic').attr('src','../images/cambodia/topic_'+id+'.png');

  //展示第一张背景图
  $('.img-view-bg').find('img').eq(0).show();

  var index =0;
  var series=0;
  var aBarrage = JSON.parse(message);
  var barrage = aBarrage.reverse();
  console.log(barrage[series]);

  //改变背景图
  var imgView = setInterval(changeBg,5000);
  function  changeBg() {
    index++;
    // console.log(index);
    if(index ==3){
      index = 0;
    }
    $('.img-view-bg').find('img').hide().eq(index).fadeIn(1000).show();
  }

  //弹幕飘屏
  var barrageAll = setInterval(getBarrage,2000);
  function getBarrage () {
    var num = parseInt(16*Math.random()+36);
    var num = num+'%'
    var content = '<div class="all-barrage barrage-move">'+barrage[series]+'</div>';
    $('.container').find('.img-view-topic').before(content);
    $('.all-barrage:last').css('top',num);
    series++;
    if(series == barrage.length){
      // clearInterval(barrageAll);
      series = 0;
    }
  }
  
  //发送弹幕
	$('.send-barrage').on('click',function  () {
		var barrage = $('.ipt-barrage').val();
    var flag = $('.send-barrage').attr('flag');
    if(flag == 1){
      alert('只能发送一次弹幕，去别的景点看看吧');
      return;
    }
		if(!barrage){
			alert('请输入弹幕');
			return ;
		}
    $('.send-barrage').attr('flag','1');  
		$('.barrage-content').text(barrage);
		$('.barrage-content').addClass('barrage-move');

    $.ajax({
      type : 'post',
      url : 'message',
      data : {
        content:barrage,
      },
      dataType : 'json',
      success : function(data){
        console.log(data);
        $('.ipt-barrage').val('');
      }
    })

	})

  //返回首页
  $('.img-return-btn').on('click',function  () {
    window.location.href="cambodia";
  })

  //关注主播
  $('.img-view-zhubo').on('click',function  () {
    $('.zhubo-show').show();
  })

  //关闭弹窗
  $('.close-btn').on('click',function  () {
    $('.zhubo-show').hide();  
  })

  $('.attention-btn').on('click',function  () {
    window.location.href='http://a.app.qq.com/o/simple.jsp?pkgname=com.lalocal.lalocal';
  })

  //分享弹幕
  $('.img-share-btn').on('click',function  () {
    $('.show-comment').show();
  })

  $('.show-comment').on('click',function  () {
    $('.show-comment').hide();
  })
})